from rest_framework import serializers
from apps.goods.models import SKU


class SKUModelSerializer(serializers.ModelSerializer):
    # TODO 把分类的字段类型修改了
    category = serializers.StringRelatedField()
    # TODO 前端还需要 category_id 的分类id数据
    category_id = serializers.IntegerField()

    sku = serializers.StringRelatedField()
    spu_id = serializers.IntegerField()

    class Meta:
        model = SKU
        fields = '__all__'


###################三级分类数据的获取########################
from apps.goods.models import GoodsCategory


class GoodsCategoryModelSerializer(serializers.ModelSerializer):
    class Meta:
        model = GoodsCategory
        fields = '__all__'


###############SPU的序列化器###############################
from apps.goods.models import SPU


class SimpleSPUModelSerializer(serializers.ModelSerializer):
    class Meta:
        model = SPU
        fields = ['id', 'name']


##############规格选项和序列化器###########################
from apps.goods.models import SPUSpecification, SpecificationOption


# 选项
class SpecificationOptionModelSerializer(serializers.ModelSerializer):
    class Meta:
        model = SpecificationOption
        fields = ['id', 'value']


# 规格
class SPUSpecificationOptionModelSerializer(serializers.ModelSerializer):
    # TODO 选项的序列化器
    options = SpecificationOptionModelSerializer(many=True)

    class Meta:
        model = SPUSpecification
        fields = ['id', 'name', 'options']
